import {
  lot_equipment_one_api,
  lot_equipmentControl_control_api,
} from "@/api/lot.js";
import { Notify } from "vant";
export default {
  components: {},
  props: {},
  data() {
    return {};
  },
  watch: {},
  mounted() {},
  methods: {
    // 设置websocket
    setWebsocket(data) {
      console.info("websocket监听开始")
      let that = this;
      if (that.$global.ws && that.$global.ws.readyState == 1) {
        console.log("websocket监听发送数据", JSON.stringify(data));
        that.$global.ws.send(JSON.stringify(data));
      }
      that.$global.ws.onmessage = function(res) {
        let obj = JSON.parse(res.data);
        if (obj.action == "reflush") {
          console.info("websocket监听接收到数据"+res.data)
          that.refreshFn();
        }
      };
    },
    // 发送设备控制
    lot_equipmentControl_control_api(obj) {
      let data = {
        equipmentId: obj.equipmentId,
        cmd: obj.cmd,
        parameter: obj.parameter,
      };
      console.info(
        "lot_equipmentControl_control_api发送设备控制入参" +
          JSON.stringify(data)
      );
      lot_equipmentControl_control_api(data)
        .then((res) => {
          console.info(
            "lot_equipmentControl_control_api发送设备控制出参" +
              JSON.stringify(res)
          );
          if (res.status == 200) {
            Notify({ type: "success", message: "设备操作成功" });
          } else {
            Notify({ type: "success", message: res.msg });
          }
        })
        .catch((err) => {
          Notify({ type: "danger", message: "设备操作失败" });
        });
    },
  },
};
